package sunlight.ui;

import java.util.Vector;

import javax.swing.JFrame;

import sunlight.core.Application;
import sunlight.logger.EventLogger;

public class UIController{
	
	//referinta catre toate ferestrele disponibile
	private Vector<JFrame> windows;
	
	public void init(){
		this.windows = new Vector<JFrame>();
	}


	public int open_window(String classname, boolean showit){
		JFrame Window;
		
		try {
			
			Window = (JFrame) Class.forName(classname).newInstance();
			
			if(showit == true){
				this.show_window(Window);
			}
			
			this.windows.add(Window);
			
			return this.windows.indexOf(Window);
			
		} catch (InstantiationException ie) {
			
			Application.Log.write(ie.toString(), EventLogger.ERROR);
		} catch (IllegalAccessException iae) {
			
			Application.Log.write(iae.toString(), EventLogger.ERROR);
		} catch (ClassNotFoundException cnfe) {
			
			Application.Log.write(cnfe.toString(), EventLogger.ERROR);
		}
		
		return -1;
	}
	
	public void show_window(JFrame Window) {
		Window.setVisible(true);
	}
	
	
	public void hide_window(JFrame Window){
		Window.setVisible(false);
	}
	
	public void close_window(int index){
		JFrame Window = (JFrame) this.windows.get(index);
		Window.dispose();
	}
	
}
